package com.i.MyString;

public class TestEqualsOverride {
    public static void main(String[] args) {
        Worker w1=new Worker("张三",18,78d);
        Worker w2=new Worker("张三",18,78d);
        System.out.println(w1==w2);
        System.out.println(w1.equals(w2));
    }
}
class Worker{
    private String name;
    private Integer age;            //整数是有缓存的，共用地址
    private Double salary;

    public Worker(String name, Integer age, Double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public Worker() {
        super();
    }


    /**对equals()方法的覆写，内容相同即相等*/
    @Override
    public boolean equals(Object obj) {
        if (this==obj){
            return true;
        }
        if (obj==null){
            return false;
        }
        if (this.getClass()!=obj.getClass()){
            return false;
        }
        Worker w=(Worker) obj;
        //Integer中的equals已经将object中的方法覆盖了
        if (this.name.equals(w.name) && this.age.equals(w.age) && this.salary.equals(w.salary)){
            return true;
        }
        return false;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }
}